---------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Dropbox\bavarian affair\merged data\replication\create_indiff2010_varia
> ble\survey_indifference2010.log
  log type:  text
 opened on:  20 Nov 2015, 19:17:37

. 
end of do-file

. do "C:\Users\tdaeuble\AppData\Local\Temp\STD05000000.tmp"

. 
. * Franconia dummy variable
. gen franconia = 0 if kkz != .

. replace franconia = 1 if kkz >= 9400 & kkz < 9700
(1,338 real changes made)

. 
. * Vote intention state-level election (which vote that is is left open, on request in
> terviewer says second)
. gen pvote = Q24

. recode pvote (6=5) (5=6) (7/14 = .) // use order as in pid variable CSU SPD FDP GRU L
> in FW
(pvote: 1316 changes made)

. 
. *long format version
. forvalues i = 1/6 {
  2. gen pvote`i' = pvote
  3. recode pvote`i' (`i' = 1) (nonmiss = 0 ) 
  4. }
(887 missing values generated)
(pvote1: 2037 changes made)
(887 missing values generated)
(pvote2: 3113 changes made)
(887 missing values generated)
(pvote3: 3113 changes made)
(887 missing values generated)
(pvote4: 3113 changes made)
(887 missing values generated)
(pvote5: 3113 changes made)
(887 missing values generated)
(pvote6: 3113 changes made)

. 
. * Party id
. gen pid1 = 0 if (Q64 != . & Q64 != 12) | (Q65 != . & Q65 != 12) // create pid var if 
> one of two (split-sample Germany vs Bavaria wording variant is ignored) pid questions
>  answered ( code 12 = keine Angabe / no response)
(103 missing values generated)

. replace pid1 = 1  if (Q64 < 4| Q65 < 4) & (Q66 == 1 | Q66 == 2 ) // use all of CDU, C
> DU/CSU, CSU (very strong or rather strong)
(517 real changes made)

. 
. forvalues i = 2/6 {
  2. gen pid`i' = 0 if (Q64 != . & Q64 != 12) | (Q65 != . & Q65 != 12)
  3. replace pid`i' = 1 if (Q64 == `i' + 2 | Q65 == `i' + 2 ) & (Q66 == 1 | Q66 == 2 ) 
  4. }
(103 missing values generated)
(290 real changes made)
(103 missing values generated)
(56 real changes made)
(103 missing values generated)
(292 real changes made)
(103 missing values generated)
(35 real changes made)
(103 missing values generated)
(33 real changes made)

. 
. * left-right distance (from 1-11 scale)
. gen lr_self = Q22

. mvdecode lr_self, mv(98 99)
     lr_self: 199 missing values generated

. replace lr_self = lr_self - 1 // recode to 0-10
(3,801 real changes made)

. gen lrdist1 = abs(lr_self-6.8) // party positions = means from 2013 MEDW election sur
> vey
(199 missing values generated)

. gen lrdist2 = abs(lr_self-3.9)
(199 missing values generated)

. gen lrdist3 = abs(lr_self-5.7)
(199 missing values generated)

. gen lrdist4 = abs(lr_self-3.6)
(199 missing values generated)

. gen lrdist5 = abs(lr_self-1)
(199 missing values generated)

. gen lrdist6 = abs(lr_self-5.3)
(199 missing values generated)

. 
. * gender
. gen female = Q56

. recode female (1 = 0 ) (2 = 1)
(female: 4000 changes made)

. 
. * age cohort
. * 2010: 18-24, 25-29, 30-39, 40-49, 50-64, 65-74, 75-
. gen AGE = 2010-Q55 if Q55 < 9990
(26 missing values generated)

. egen resp_agecat = cut(AGE), at(0 30(10)60 100) // >= category label < next cat label
(26 missing values generated)

. qui tab resp_agecat, gen(resp_agecat_gr)

. 
. * 'high education level' (Fachhochschulreife or Abitur)
. gen higheduc = Q57

. recode higheduc ( 4 5 =  1) (1/3 6/9 = 0)  // still in school, don't know, other, no 
> response are all subsumed under 0
(higheduc: 4000 changes made)

. 
. * religion (ref: no religion; don't know) 
. gen religion = Q63

. recode religion (1 = 1) (2 = 2) (3/6 =3) 
(religion: 831 changes made)

. * 1 catholic, 2 protestant, 3 other/none/don't know/keine Angabe 
. 
. * Note: in comparison to the 2013 election survey, there is no information on compete
> nce ratings, economic assessements, or union membership info in this survey
. 
. sum pvote* pid* lrdist* female resp_agecat_gr2-resp_agecat_gr5 higheduc i.relig franc
> onia

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       pvote |      3,113    2.726951    1.662561          1          6
      pvote1 |      3,113    .3456473    .4756553          0          1
      pvote2 |      3,113    .2014134    .4011206          0          1
      pvote3 |      3,113    .0607131    .2388417          0          1
      pvote4 |      3,113     .254417    .4356029          0          1
-------------+---------------------------------------------------------
      pvote5 |      3,113     .048185    .2141914          0          1
      pvote6 |      3,113    .0896242    .2856884          0          1
        pid1 |      3,897    .1326662    .3392571          0          1
        pid2 |      3,897    .0744162    .2624807          0          1
        pid3 |      3,897      .01437    .1190259          0          1
-------------+---------------------------------------------------------
        pid4 |      3,897    .0749294    .2633112          0          1
        pid5 |      3,897    .0089813    .0943551          0          1
        pid6 |      3,897    .0084681    .0916433          0          1
     lrdist1 |      3,801    2.681084    1.537928         .2        6.8
     lrdist2 |      3,801    1.455275    1.323209         .1        6.1
-------------+---------------------------------------------------------
     lrdist3 |      3,801    1.909629    1.330557         .3        5.7
     lrdist4 |      3,801    1.582741    1.317413         .4        6.4
     lrdist5 |      3,801    3.434096    1.792069          0          9
     lrdist6 |      3,801    1.683899    1.295163         .3        5.3
      female |      4,000        .523    .4995332          0          1
-------------+---------------------------------------------------------
resp_ageca~2 |      3,974    .1444389    .3515784          0          1
resp_ageca~3 |      3,974    .2478611    .4318251          0          1
resp_ageca~4 |      3,974    .2055863    .4041803          0          1
resp_ageca~5 |      3,974    .2649723     .441374          0          1
    higheduc |      4,000       .4035    .4906607          0          1
             |
    religion |
          2  |      4,000      .24925    .4326329          0          1
          3  |      4,000        .235    .4240518          0          1
             |
   franconia |      4,000       .3345    .4718744          0          1

. gen respid = _n

. 
. keep respid persgew  pvote?  pid*  lrdist* relig franconia higheduc female resp_age* 
>  

. * keep respid gkz persgew  pvote?  pid*  lrdist* relig franconia higheduc female resp
> _age*  
. 
. reshape long pvote pid  lrdist , i(respid) j(party_num)
(note: j = 1 2 3 4 5 6)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                     4000   ->   24000
Number of variables                  30   ->      16
j variable (6 values)                     ->   party_num
xij variables:
               pvote1 pvote2 ... pvote6   ->   pvote
                     pid1 pid2 ... pid6   ->   pid
            lrdist1 lrdist2 ... lrdist6   ->   lrdist
-----------------------------------------------------------------------------

. 
. *******************************
. *** conditional logit model ***
. *******************************
. 
. global fcontrols "pid lrdist"

. global fcasecntrls "female resp_agecat_gr2-resp_agecat_gr5 higheduc i.relig franconia
>   "

. 
. 
. xi: asclogit pvote $fcontrols [iw=persgew] , case(respid) alt(party_num) base(1) case
> vars($fcasecntrls) 
i.religion        _Ireligion_1-3      (naturally coded; _Ireligion_1 omitted)
note: variable pid has 1835 cases that are not alternative-specific: there is no
      within-case variability

Iteration 0:   log likelihood = -9338.3148  
Iteration 1:   log likelihood = -9274.7652  
Iteration 2:   log likelihood =  -7635.337  
Iteration 3:   log likelihood = -5327.3345  
Iteration 4:   log likelihood = -3494.1224  
Iteration 5:   log likelihood = -3179.9107  
Iteration 6:   log likelihood = -3151.0474  
Iteration 7:   log likelihood = -3150.8562  
Iteration 8:   log likelihood = -3150.8562  

Alternative-specific conditional logit         Number of obs      =     17,874
Case variable: respid                          Number of cases    =       2979

Alternative variable: party_num                Alts per case: min =          6
                                                              avg =        6.0
                                                              max =          6

                                                  Wald chi2(47)   =    1377.17
Log likelihood = -3150.8562                       Prob > chi2     =     0.0000

---------------------------------------------------------------------------------
          pvote |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------+----------------------------------------------------------------
party_num       |
            pid |   3.332848   .1075136    31.00   0.000     3.122126    3.543571
         lrdist |   -.339096   .0210589   -16.10   0.000    -.3803708   -.2978213
----------------+----------------------------------------------------------------
1               |  (base alternative)
----------------+----------------------------------------------------------------
2               |
         female |   .0947759    .131302     0.72   0.470    -.1625714    .3521231
resp_agecat_gr2 |  -.1475017   .2385122    -0.62   0.536     -.614977    .3199737
resp_agecat_gr3 |   .4805636   .2174871     2.21   0.027     .0542967    .9068305
resp_agecat_gr4 |   .6984554   .2332472     2.99   0.003     .2412993    1.155611
resp_agecat_gr5 |   .4101687   .1968864     2.08   0.037     .0242784     .796059
       higheduc |   .2586501    .163934     1.58   0.115    -.0626547    .5799548
   _Ireligion_2 |   .1405681    .160288     0.88   0.381    -.1735906    .4547268
   _Ireligion_3 |   .8979331   .1786666     5.03   0.000     .5477531    1.248113
      franconia |   .3718404   .1398813     2.66   0.008     .0976781    .6460028
          _cons |  -1.762035   .1963649    -8.97   0.000    -2.146903   -1.377167
----------------+----------------------------------------------------------------
3               |
         female |   .1419731   .1982741     0.72   0.474    -.2466371    .5305832
resp_agecat_gr2 |   .2367644   .2986561     0.79   0.428    -.3485908    .8221196
resp_agecat_gr3 |   .0346515   .3168497     0.11   0.913    -.5863625    .6556655
resp_agecat_gr4 |   .2712142   .3413721     0.79   0.427    -.3978627    .9402912
resp_agecat_gr5 |   -.226529   .3020941    -0.75   0.453    -.8186225    .3655645
       higheduc |   .8399888   .2165826     3.88   0.000     .4154947    1.264483
   _Ireligion_2 |   .0831962   .2549952     0.33   0.744    -.4165853    .5829777
   _Ireligion_3 |   .8904564   .2484211     3.58   0.000     .4035601    1.377353
      franconia |  -.1612765   .2211012    -0.73   0.466    -.5946269    .2720739
          _cons |   -2.43689   .2730416    -8.92   0.000    -2.972042   -1.901738
----------------+----------------------------------------------------------------
4               |
         female |   .2705325   .1287513     2.10   0.036     .0181845    .5228805
resp_agecat_gr2 |   .1299482   .2155853     0.60   0.547    -.2925912    .5524876
resp_agecat_gr3 |   .5464245   .2057475     2.66   0.008     .1431668    .9496822
resp_agecat_gr4 |   .8631202   .2216553     3.89   0.000     .4286837    1.297557
resp_agecat_gr5 |   .0885263   .1964606     0.45   0.652    -.2965295     .473582
       higheduc |   .7764613   .1500513     5.17   0.000     .4823661    1.070556
   _Ireligion_2 |    .178823   .1582207     1.13   0.258     -.131284    .4889299
   _Ireligion_3 |   .8063085   .1750553     4.61   0.000     .4632064    1.149411
      franconia |   .0751307   .1396145     0.54   0.590    -.1985088    .3487702
          _cons |   -1.68097   .1888841    -8.90   0.000    -2.051176   -1.310764
----------------+----------------------------------------------------------------
5               |
         female |   -.267642    .209481    -1.28   0.201    -.6782172    .1429333
resp_agecat_gr2 |   .6140059   .3722612     1.65   0.099    -.1156126    1.343624
resp_agecat_gr3 |   .9948983   .3564253     2.79   0.005     .2963176    1.693479
resp_agecat_gr4 |    1.42075   .3667895     3.87   0.000     .7018558    2.139644
resp_agecat_gr5 |   .6151519   .3465833     1.77   0.076    -.0641388    1.294443
       higheduc |  -.2518376   .2803924    -0.90   0.369    -.8013965    .2977214
   _Ireligion_2 |  -.0068079   .2795921    -0.02   0.981    -.5547982    .5411825
   _Ireligion_3 |   1.169233   .2483358     4.71   0.000      .682504    1.655962
      franconia |   .0947551   .2200858     0.43   0.667    -.3366052    .5261154
          _cons |  -2.552559   .3243388    -7.87   0.000    -3.188251   -1.916866
----------------+----------------------------------------------------------------
6               |
         female |   .0020578   .1502488     0.01   0.989    -.2924245      .29654
resp_agecat_gr2 |     .00924   .2736104     0.03   0.973    -.5270265    .5455064
resp_agecat_gr3 |   .9103584   .2378228     3.83   0.000     .4442344    1.376483
resp_agecat_gr4 |   .5685279   .2689483     2.11   0.035      .041399    1.095657
resp_agecat_gr5 |   .0656994   .2392715     0.27   0.784    -.4032642    .5346629
       higheduc |  -.0087271    .194933    -0.04   0.964    -.3907887    .3733346
   _Ireligion_2 |  -.2442295   .1932046    -1.26   0.206    -.6229034    .1344445
   _Ireligion_3 |   .1917768   .2209467     0.87   0.385    -.2412708    .6248244
      franconia |  -.1465085    .168367    -0.87   0.384    -.4765018    .1834848
          _cons |  -1.542783   .2178915    -7.08   0.000    -1.969842   -1.115723
---------------------------------------------------------------------------------

. predict prob_w
(option pr assumed; Pr(party_num))

. 
. * check: is csu vote correctly predicted?
. gen csu_correct = 0 if party_num == 1 & pvote != . 
(20,887 missing values generated)

. replace csu_correct = 1 if csu_correct == 0 & party_num == 1 & ( (pvote == 1 & prob_w
>  > .5 & prob_w != .) |  ( pvote == 0  & prob_w < .5))
(2,384 real changes made)

. tab csu_correct if party_num == 1

csu_correct |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        729       23.42       23.42
          1 |      2,384       76.58      100.00
------------+-----------------------------------
      Total |      3,113      100.00

. tab csu_correct if party_num == 1 & e(sample)

csu_correct |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        595       19.97       19.97
          1 |      2,384       80.03      100.00
------------+-----------------------------------
      Total |      2,979      100.00

. 
. keep if party_num == 1
(20,000 observations deleted)

. gen indiff_w = prob_w*(1-prob_w)
(296 missing values generated)

. 
. /*
> * The variable indiff_w is now aggregated to the SMD level.
> 
> keep gkz persgew indiff
> 
> * merge mapping of community to SMD
> gen schlsselnr = gkz-9000000
> merge m:1 schlsselnr using "ZA5363\2014-10-06-Mapping Gemeinde Stimmkreis.dta"
> drop if _m == 2 // 844 of in total 2056 Gemeinden / local communities not in Survey
> drop _m
> 
> 
> tab stimmkreisnrltw2013
> di (456+164+81)/4000 
> * for 17.5% of cases the SMD cannot be uniquely identified, since there are several S
> MDs in large cities 
> * (Muenchen 101-108, Nuernberg 501-504,Augsburg 701-702)
> * use the city-level value for all these SMDs in aggregate analysis
> 
> * some parts of these large city SMDs can be identified (neighbouring communities):
> * Nuernberg Sued 503: 565000 Schwabach 
> * Nuernberg Ost 502: 574123 Feucht; also Rueckersdorf, Schwaig
> * 702: Gersthofen; Neusaess
> * -> add them to the respective city as a whole
> gen stk_code = stimmkreisnrltw2013
> replace stk_code = "501-504" if stimmkreisnrltw2013 == "502" | stimmkreisnrltw2013 ==
>  "503"
> replace stk_code = "701-702" if stimmkreisnrltw2013 == "702" 
> 
> collapse (mean) indiff2010 =indiff_w (count) N_indiff2010=indiff_w  [iw=persgew], by(
> stk_code)
> gen year = 2013
> 
> * save and merge this with aggregate data
> save indiff2010.dta, replace
> 
> */
. 
. log close
      name:  <unnamed>
       log:  C:\Dropbox\bavarian affair\merged data\replication\create_indiff2010_varia
> ble\survey_indifference2010.log
  log type:  text
 closed on:  20 Nov 2015, 19:17:44
---------------------------------------------------------------------------------------
